﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;

[CustomEditor(typeof(Animation))]
public class AnimationEditor : Editor
{
    private SerializedObject obj;
    private SerializedProperty lightmapIndex;
    Animation targetobj;
    List<AnimationState> enableStates = new List<AnimationState>();
    void OnEnable()
    {
        targetobj = target as Animation;
        obj = new SerializedObject(target);
        //lightmapIndex = obj.FindProperty("_lightmapIndex");
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        obj.Update();

        enableStates.Clear();
        foreach (AnimationState animState in targetobj)
        {
            if (animState.enabled)
            {
                enableStates.Add(animState);
            }
        }
        EditorGUILayout.BeginVertical("HelpBox");
        EditorGUILayout.TextField("WarpMode",targetobj.wrapMode.ToString());
        if (enableStates.Count > 0)
        {
            EditorGUILayout.LabelField("当前正在播放的动画片段:");
            foreach (AnimationState animState in enableStates)
            {
                EditorGUILayout.TextField("ClipName",animState.name);
            }
        }
        else
        {
            EditorGUILayout.LabelField("No Playing Clips");
        }
        EditorGUILayout.EndVertical();
        
        //EditorGUILayout.PropertyField(lightmapIndex);
        //targetobj.lightmapIndex = EditorGUILayout.IntField("lightmapIndex", targetobj.lightmapIndex);
        //targetobj.lightmapScaleOffset = EditorGUILayout.Vector4Field("lightmapScaleOffset", targetobj.lightmapScaleOffset);
        //不对这两处改动进行保存
        obj.ApplyModifiedProperties();
    }
}
